package behavioral.template;

/**
 * 模板模式
 * 抽出公共部分
 */

abstract class Game{
    protected abstract void init();
    protected abstract void start();
    protected abstract void end();

    public final void play(){
        System.out.println("初始化");
        init();
        System.out.println("开始游戏");
        start();
        System.out.println("结束");
        end();
    }
}

class Snake extends Game{

    @Override
    protected void init() {
        System.out.println("初始化贪吃蛇");
    }

    @Override
    protected void start() {
        System.out.println("开始贪吃蛇");
    }

    @Override
    protected void end() {
        System.out.println("结束游戏");
    }
}

class Test{
    public static void main(String[] args) {
        Game game = new Snake();

        game.play();
    }
}